/* 
 * Copyright 2014 Igor Maznitsa (http://www.igormaznitsa.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.igormaznitsa.jhexed.swing.editor.ui.dialogs;

import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.event.ActionEvent;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

public class DialogAbout extends AbstractDialog {
  private static final long serialVersionUID = -8850290336144697768L;

  public DialogAbout(java.awt.Frame parent) {
    super(parent, true);
    initComponents();
    this.editorText.addHyperlinkListener(new HyperlinkListener() {
      @Override
      public void hyperlinkUpdate(HyperlinkEvent e) {
        if (e.getEventType()==HyperlinkEvent.EventType.ENTERED){
          editorText.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        } else if (e.getEventType() == HyperlinkEvent.EventType.EXITED){
          editorText.setCursor(Cursor.getDefaultCursor());
        } else {
          try {
            Desktop.getDesktop().browse(e.getURL().toURI());
          }
          catch (Exception ex) {
            ex.printStackTrace();
          }
        }
      }
    });
    pack();
  }

  /**
   * This method is called from within the constructor to initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is always
   * regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    buttonClose = new javax.swing.JButton();
    labelImage = new javax.swing.JLabel();
    jScrollPane1 = new javax.swing.JScrollPane();
    editorText = new javax.swing.JEditorPane();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setTitle("About");
    setLocationByPlatform(true);

    buttonClose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/igormaznitsa/jhexed/swing/editor/icons/cross.png"))); // NOI18N
    buttonClose.setText("Close");
    buttonClose.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        buttonCloseActionPerformed(evt);
      }
    });

    labelImage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/igormaznitsa/jhexed/swing/editor/icons/logo.png"))); // NOI18N

    editorText.setEditable(false);
    editorText.setContentType("text/html"); // NOI18N
    editorText.setText("<html><body> <h2>JHexed Map Editor</h2>  <p>Author: igor Maznitsa (<a href=\"http://www.igormaznitsa.com\">http://www.igormaznitsa.com</b>)</p> <hr>  <p>The Utility allows to edit multilevel hexagonal maps with SVG icons and background.</p>    <hr> <h3>Licenses</h3> <ul> <li>JHexed framework: Apache License 2.0 (<a href=\"https://code.google.com/p/jhexed/\">https://code.google.com/p/jhexed/</a>) </li> <li>Apache™ Batik SVG Toolkit: Apache License 2.0 (<a href=\"http://xmlgraphics.apache.org/batik/\">http://xmlgraphics.apache.org/batik/</a>)</li> <li>SwingX framework: LGPL (<a href=\"https://swingx.java.net//\">https://swingx.java.net/</a>)</li> <li>Fugue Icons: CCA 3.0 License (<a href=\"http://p.yusukekamiyamane.com/\">http://p.yusukekamiyamane.com/</a>)</li> <li>Free Vintage Design Icons: CCA 3.0 License (<a href=\"http://www.designcontest.com/free-icons/\">http://www.designcontest.com/free-icons/</a>)</li> </ul> </body></html>");
    jScrollPane1.setViewportView(editorText);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
          .addComponent(buttonClose, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
          .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
            .addComponent(labelImage)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)))
        .addContainerGap())
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
        .addContainerGap()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
            .addComponent(labelImage)
            .addGap(0, 90, Short.MAX_VALUE))
          .addComponent(jScrollPane1))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(buttonClose)
        .addContainerGap())
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

  private void buttonCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCloseActionPerformed
    dispose();
  }//GEN-LAST:event_buttonCloseActionPerformed

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton buttonClose;
  private javax.swing.JEditorPane editorText;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JLabel labelImage;
  // End of variables declaration//GEN-END:variables

  @Override
  public void processEscape(ActionEvent e) {
    buttonCloseActionPerformed(e);
  }
}
